package com.person.jc.web.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.person.jc.common.Constants;
import com.person.jc.entity.TsUser;
import com.person.jc.service.service.BsOrderService;
import com.person.jc.utils.DateUtils;
import com.person.jc.utils.JsonMapper;
import com.person.jc.utils.Servlets;
import com.person.jc.utils.SessionKit;
import com.person.jc.utils.Utils;

/**
 * fcl维修接单
 */
public class MyBsOrderController extends Controller {
	
	
	public void init(){
		setAttr("menuId", getPara("menuId"));
		setAttr("startDate",DateUtils.formatDate(DateUtils.addMonths(new Date(), -1), "yyyy-MM-dd"));
		setAttr("endDate",DateUtils.getDate());
		String orderType = getPara("orderType");//1. 检测接单
		if("1".equals(orderType)){
			render("mycheck/main.jsp");
		}else{
			render("myrepair/main.jsp");
		}
	}
	
	public void list(){
		Map<String, Object> map = Servlets.getParametersStartingWith(getRequest(), "p_");
		TsUser tsUser = (TsUser)SessionKit.get().getAttribute(Constants.LOGIN_USER);
		map.put("serviceUser", tsUser.getUserId());
		List<Record> list = BsOrderService.me.getList(map);
		setAttr("list", list);
		String orderType = String.valueOf(map.get("orderType"));
		if("1".equals(orderType)){
			render("mycheck/list.jsp");
		}else{
			render("myrepair/list.jsp");
		}
	}
	
	public void edit(){
		String orderId = getPara("orderId");
		String taskType = getPara("taskType");
		String view = getPara("view");
		if(Utils.isNotEmpty(orderId)){
			Record order = BsOrderService.me.getOrderInfo(orderId);
			List<Record> detail = BsOrderService.me.getOrderDetail(orderId, taskType);
			setAttr("obj", order);
			setAttr("details", detail);
			if(detail.size() > 0){
				setAttr("detailsJson", JsonMapper.nonDefaultMapper().toJson(detail));
			}else{
				setAttr("detailsJson", "[]");
			}
		}else{
			setAttr("detailsJson", "[]");
		}
		setAttr("view", view);
		setAttr("taskType", taskType);
		String orderType = getPara("orderType");
		if("1".equals(orderType)){
			render("mycheck/edit.jsp");
		}else{
			render("myrepair/edit.jsp");
		}
	}

	
}
